<template>
  <div class="page-container">
    <div class="box-wrapper" v-if="thirdServiceDetail.ifOpenViolation !== ''">
      <div class="logo-title-wrapper">
        <span class="title">违章查询</span>
        <span class="open" v-if="thirdServiceDetail.ifOpenViolation">已开通</span>
        <span class="close" v-else>暂未开通</span>
      </div>
      <div class="text" v-if="!thirdServiceDetail.ifOpenViolation"> 如需开通违章查询服务请联系启程的工作人员 </div>
      <div class="more-bills" v-if="isviolationPermissoin" @click="goTo"> 前往违章查询<icon-right /> </div>

      <!-- 已开通-->
      <div class="payee-box grid grid-cols-3" v-if="thirdServiceDetail.ifOpenViolation">
        <template v-for="(item, index) in dataList" :key="index">
          <div class="payee">
            <p>{{ item.label }}</p>
            <p class="payee-value">{{ item.value }} {{ item.unit }}</p>
          </div>
          <a-divider v-if="index % 2 == 0" class="divider" direction="vertical" />
        </template>
      </div>

      <!-- 未开通-->
      <template v-else>
        <div class="money" v-for="(item, index) in serviceList" :key="index">
          <img :src="item.icon" width="54" height="54" />
          <div class="msg">
            <div class="money-title">{{ item.title }}</div>
            <div class="money-text">{{ item.desc }}</div>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script setup>
  import { ref, reactive, computed } from 'vue'
  import { useRouter } from 'vue-router'
  import { getAccountInfo } from '@/api/asset/carViolation'
  import { usePermission } from '@/hooks/usePermission'
  const router = useRouter()
  const serviceList = ref([
    {
      title: '多企业账号同时登录',
      desc: '支持设置多个查询账号',
      icon: new URL(`@/assets/polymerisation_1.png`, import.meta.url).href,
    },
    {
      title: '批量查询',
      desc: '随时随地批量查询违章',
      icon: new URL(`@/assets/polymerisation_2.png`, import.meta.url).href,
    },
    {
      title: '协助创建',
      desc: '系统协助自动创建违章订单并查找关联单号',
      icon: new URL(`@/assets/polymerisation_3.png`, import.meta.url).href,
    },
  ])
  const dataList = computed(() => {
    return [
      {
        label: '账户余额：',
        value: thirdServiceDetail.accountAmount || 0,
        unit: '元',
      },
      {
        label: '有效查询总数：',
        value: thirdServiceDetail.validQueryCount || 0,
        unit: '条',
      },
      {
        label: '收费标准：',
        value: thirdServiceDetail.price || 0,
        unit: '元/条',
      },
      {
        label: '收费总额：',
        value: thirdServiceDetail.allAmount || 0,
        unit: '元',
      },
    ]
  })
  const isviolationPermissoin = computed(() => {
    // 没有权限 不展示
    return thirdServiceDetail.ifOpenViolation && usePermission('svms:asstes:violation:query')
  })

  // 违章查询详情
  const initThirdService = {
    accountAmount: '', // 账户余额
    validQueryCount: '', // 有效查询总数
    price: '', // 收费标准
    allAmount: '', // 收款总额
    ifOpenViolation: '', // 是否开通违章查询
  }
  // 服务状态
  const thirdServiceDetail = reactive({ ...initThirdService })
  const getDetailApi = () => {
    getAccountInfo().then(({ result }) => {
      Object.assign(thirdServiceDetail, result)
    })
  }

  const goTo = () => {
    // 跳转违章查询
    router.push({ path: '/assets/violation/query' })
  }

  getDetailApi()
</script>

<style lang="less" scoped>
  .page-container {
    .more-bills {
      color: #1890ff;
      cursor: pointer;
      font-weight: 500;
      font-size: 16px;
      margin-top: 20px;
    }
    .payee-box {
      margin-top: 24px;
      row-gap: 24px;
    }
    .payee {
      font-weight: 400;
      font-size: 16px;
      color: #4e5969;
    }
    .payee-value {
      font-weight: 600;
      font-size: 18px;
      color: #1890ff;
      margin-top: 4px;
    }
    .divider {
      margin: 0 40px;
    }
    .box-wrapper {
      display: flex;
      justify-content: flex-start;
      flex-direction: column;
      align-items: flex-start;
      width: 100%;
      height: 80vh;
      padding: 74px 0 0 57px;
      background-image: url('../../../assets/box-bg.png') !important;
      background-size: cover;

      .logo-title-wrapper {
        position: relative;
        .title {
          font-weight: 500;
          font-size: 32px;
          color: #1d2129;
          line-height: 40px;
        }
        .open,
        .close {
          vertical-align: top;
          padding: 2px 10px;
          font-weight: 600;
          font-size: 12px;
          color: #ffffff;
          background: linear-gradient(222deg, #ff7a66 0%, #ff5b60 100%);
          border-radius: 60px;
          border-bottom-left-radius: 0;
          border-top-left-radius: 30px;
        }
        .close {
          color: #919aa5;
          background: linear-gradient(222deg, #f2f3f5 0%, #dbdbdb 100%);
        }
      }
      .text {
        font-weight: 400;
        font-size: 14px;
        color: #919aa5;
        margin: 12px 0 20px 0;
      }
      .money {
        display: flex;
        align-items: center;
        margin-top: 20px;
        .money-title {
          font-weight: 500;
          font-size: 16px;
          color: #1d2129;
          margin-bottom: 3px;
        }
        .money-text {
          font-weight: 400;
          font-size: 12px;
          color: #919aa5;
        }
      }
    }
  }
</style>
